/*
 *  POJ3087: Shuffle'm Up
 */

/*-------- Includes --------*/
#include <map>
#include <string>
#include <cstring>
#include <iostream>

using namespace std;

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    int nOfCase;

    cin >> nOfCase;

    for (int k = 0; k < nOfCase; k++) {
        int n;

        cin >> n;

        char stk[2 * n + 1];
        char aux[2 * n + 1];
        char tgt[2 * n + 1];

        cin >> stk >> (stk + n) >> tgt;

        map<string, bool> dict;
        int               cnt = 0;

        dict[stk] = true;

        while (true) {
            // shuffle
            strcpy(aux, stk);
            for (int i = 0; i < n; i++) {
                stk[2 * i + 1] = aux[i];
                stk[2 * i]     = aux[i + n];
            }
            cnt++;

            // if match the target
            if (strcmp(stk, tgt) == 0) {
                cout << (k + 1) << " " << cnt << endl;
                break;
            }

            // if enter a loop
            if (dict[stk]) {
                cout << (k + 1) << " " << -1 << endl;
                break;
            }

            dict[stk] = true;
        }
    }

    return 0;
}
